package org.tabcap.gui.menu.code;

import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import org.tabcap.TCInstance;

import static java.awt.event.InputEvent.*;

public class TCCodeMenu extends JMenu
{
	private static final long serialVersionUID = -2565766424662738118L;

	public TCCodeMenu(TCInstance manager)
	{
		super("Code");
		addOption("Compile", manager.compileAction(), 'C', SHIFT_DOWN_MASK | CTRL_DOWN_MASK);
		addOption("Run", manager.runAction(), 'R', SHIFT_DOWN_MASK | CTRL_DOWN_MASK);
	}
	
	public void addOption(String name, ActionListener listener)
	{
		JMenuItem option = new JMenuItem(name);
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
	
	public void addOption(String name, ActionListener listener, Character keyChar, int modifiers)
	{
		JMenuItem option = new JMenuItem(name);
		option.setAccelerator(KeyStroke.getKeyStroke(keyChar, modifiers));
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
}